<?php
require("includes/constantesMvial.php");

$pagename=CHOOSE_CAT;
$lUseTree=1;
include_once("header_inc.php");

check_valid_user("");
include_once("member_header.php");
$set_add_ad_cat = "";

if (isset($_REQUEST["set_add_ad_cat"])) {
	$set_add_ad_cat = round($_REQUEST["set_add_ad_cat"]);
}

if (isset($_REQUEST["catid"])) {
	$catid = round($_REQUEST["catid"]);
}

$tplAddAd=new TplLoad;
$tplAddAd->assign("set_add_quik", $set_add_quik);
$tplAddAd->assign("set_add_tree", $set_add_tree);
$frontpage=2;

$lCatTreeParent=getParamInt("cat_tree_parent","0");
$tplAddAd->assign("parent",$lCatTreeParent);
$tplAddAd->assign("tree_name", "d");
$lCatTree=build_cat_tree($lCatTreeParent,"d",1);
//$tplAddAd->assign("tree",$lCatTree);

//TREE Ventas
$lCatTreeParent=ID_CAT_COMPRA; //getParamInt("cat_tree_parent","0");
$tplAddAd->assign("parentV", $lCatTreeParent);
$tplAddAd->assign("tree_nameV", "ventas");
$lCatTreeV=build_cat_tree2($lCatTreeParent,"ventas",1);
$tplAddAd->assign("treeV",$lCatTreeV);

//TREE Alquieler
$lCatTreeParent=ID_CAT_ALQUILER; //getParamInt("cat_tree_parent","0");
$tplAddAd->assign("parentA", $lCatTreeParent);
$tplAddAd->assign("tree_nameA", "alquiler");
$lCatTreeV=build_cat_tree2($lCatTreeParent,"alquiler",1);
$tplAddAd->assign("treeA",$lCatTreeV);

//TREE Servicios
$lCatTreeParent=ID_CAT_SERVICIOS; //getParamInt("cat_tree_parent","0");
$tplAddAd->assign("parentS", $lCatTreeParent);
$tplAddAd->assign("tree_nameS", "servicios");
$lCatTreeV=build_cat_tree2($lCatTreeParent,"servicios",1);
$tplAddAd->assign("treeS",$lCatTreeV);

/*******Obtenemos el último ID, para luego chequear que se haya renderizado*************/
$substrr 	 = "payment_options.php?catid=";
$pos_start   = strripos($lCatTreeV, $substrr);
if ($pos_start !== false) {
		$pos_end = strpos($lCatTreeV, "'",$pos_start+strlen($substrr));
		if($pos_end !== false){			
			$id_last_element = substr($lCatTreeV, $pos_start+strlen($substrr), $pos_end-($pos_start+strlen($substrr)));
			if(!empty($id_last_element)){
				$tplAddAd->assign("last_element",$substrr.$id_last_element);
			}
		}
}

if($pos_start === false ||$pos_end === false || empty($id_last_element)){
	$tplAddAd->assign("last_element","");
}
/*****************/

$option_list="";
if ($set_add_quik==1)
{
	$option_list=getCategoriesDD(getParam("catid",""),1);
	$tplAddAd->assign("option_list", $option_list);
}

$tplAddAd->display("add_ad.tpl");
include_once("member_footer.php");
include_once("footer_inc.php");
?>
